package com.example.home;

import com.example.home.Dao.*;
import com.example.home.Entities.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;
import java.util.Collections;

@SpringBootApplication
public class HomeApplication {

	@Autowired
	StudentRepository studentRepository;

	@Autowired
	CateRepository cateRepository;

	@Autowired
	CollageRepository collageRepository;

	@Autowired
	CourseRepository courseRepository;

	@Autowired
	MajorsRepository majorsRepository;

	@Autowired
	TeacherRepository teacherRepository;


	public static void main(String[] args) {

		SpringApplication.run(HomeApplication.class, args);

	}

	@Bean
	CommandLineRunner runner(){
		return args -> {
			Student stu1 = new Student("张三",1,"男","信息学院","计算机",1230);
			Student stu2 = new Student("李四",2,"女","森林保护","森林保护",4560);
			Student stu3 = new Student("王五",3,"男","法律学院","法学",7890);
			Student stu4 = new Student("李军",4,"男","信息学院","计算机",1231);
			Student stu5 = new Student("张凤",5,"女","经济学院","经济管理",1232);
			Student stu6 = new Student("古年",6,"男","信息学院","计算机",1233);


			Teacher tea1 = new Teacher("熊大",7,"101","某动画片森林学教授，毕业于熊出没大学，职位：森林信息学院副教授......");
			Teacher tea2 = new Teacher("熊二",8,"102","某动画片森林学教授，毕业于熊出没大学，职位：森林经济学院副教授......");
			Teacher tea3 = new Teacher("吉吉",9,"103","某动画片森林学教授，毕业于熊出没大学，职位：森林保护学院老师......");
			Teacher tea4 = new Teacher("毛毛",10,"104","某动画片森林学教授，毕业于熊出没大学，职位：森林法律学学院老师.....");


			Cate ca1 = new Cate("森林保护1班",11,"210","森林保护");
			Cate ca2 = new Cate("森林法律2班",12,"211","森林法学");
			Cate ca3 = new Cate("森林信息3班",13,"212","森林信息");
			Cate ca4 = new Cate("森林经济4班",14,"213","森林经济");

			Collage co1 = new Collage("保护学院",15);
			Collage co2 = new Collage("法律学院",16);
			Collage co3 = new Collage("信息学院",17);
			Collage co4 = new Collage("经济学院",18);

			Majors ma1 = new Majors("森林保护",19,"保护学院");
			Majors ma2 = new Majors("森林法学",20,"法律学院");
			Majors ma3 = new Majors("森林信息",21,"信息学院");
			Majors ma4 = new Majors("森林经济",22,"经济学院");

			Course cou1 = new Course("保护学院","森林保护","森林保护措施",23,"该课程根据地理学讲述森林覆盖面积，森林的形成、生长环境、一般寿命，及如何防护自然灾害，如何种植培养树木。","必修");
			Course cou2 = new Course("法律学院","森林法学","森林法规法则",24,"该课程根据宪法讲述森林的归属权、规划、破坏、保护、植被等相关法律、法则、准则","必修");
			Course cou3 = new Course("信息学院","森林信息","森林信息工程",25,"该课程根据信息学讲述如何使用科技、大数据、实现森林的生长环境预测、土壤成分预测，预测将要面临的自然灾害，以及如何预防","必修");
			Course cou4 = new Course("经济学院","森林经济","森林经济规划",26,"该课程根据经济学讲述森林的规划能够带来多大规划，能够给国家土地资源使用紧张的情况下带来怎样的收益，围绕如何解决城市、环境、人口、农业、林业、牧业、渔业等方面","必修");

			//设定双方关系
		//	tea1.addStudent(stu1);
		//	tea2.addStudent(stu5);
		//	tea3.addStudent(stu2);
		//	tea4.addStudent(stu3);
		//	tea1.addStudent(stu4);
		//	tea1.addStudent(stu6);

			//设定双方关系
		//	stu1.setTeacherThree(Arrays.asList(tea1));
		//	stu2.setTeacherThree(Arrays.asList(tea3));
		//	stu3.setTeacherThree(Arrays.asList(tea4));
		//	stu4.setTeacherThree(Arrays.asList(tea1));
		//	stu5.setTeacherThree(Arrays.asList(tea2));
		//	stu6.setTeacherThree(Arrays.asList(tea1));

			studentRepository.save(stu1);
			studentRepository.save(stu2);
			studentRepository.save(stu3);
			studentRepository.save(stu4);
			studentRepository.save(stu5);
			studentRepository.save(stu6);


			//
			teacherRepository.save(tea1);
			teacherRepository.save(tea2);
			teacherRepository.save(tea3);
			teacherRepository.save(tea4);

			/////////////////////////////////////////////////////
/*
			ca1.addStudent(stu2);
			ca2.addStudent(stu3);
			ca3.addStudent(stu1);
			ca3.addStudent(stu4);
			ca3.addStudent(stu6);
			ca4.addStudent(stu5);

			//确定双方关系
			stu1.setCateTwo(ca3);
			stu4.setCateTwo(ca3);
			stu6.setCateTwo(ca3);
			stu2.setCateTwo(ca1);
			stu3.setCateTwo(ca2);
			stu5.setCateTwo(ca4);


 */
			//
			cateRepository.save(ca1);
			cateRepository.save(ca2);
			cateRepository.save(ca3);
			cateRepository.save(ca4);



			//////////////////////////////////////////////////////////////
/*
			co1.addStudent(stu2);
			co2.addStudent(stu3);
			co3.addStudent(stu1);
			co3.addStudent(stu4);
			co3.addStudent(stu6);
			co4.addStudent(stu5);

			stu1.setCollageOne(co3);
			stu2.setCollageOne(co1);
			stu3.setCollageOne(co2);
			stu4.setCollageOne(co3);
			stu5.setCollageOne(co4);
			stu6.setCollageOne(co3);


 */
			collageRepository.save(co1);
			collageRepository.save(co2);
			collageRepository.save(co3);
			collageRepository.save(co4);



			////////////////////////////////////////////////////////////////////////
/*
			ma1.addStudent(stu2);
			ma2.addStudent(stu3);
			ma3.addStudent(stu1);
			ma3.addStudent(stu4);
			ma3.addStudent(stu6);
			ma4.addStudent(stu5);

			stu1.setMajorsTwo(ma3);
			stu2.setMajorsTwo(ma1);
			stu3.setMajorsTwo(ma2);
			stu4.setMajorsTwo(ma3);
			stu5.setMajorsTwo(ma4);
			stu6.setMajorsTwo(ma3);


 */
			majorsRepository.save(ma1);
			majorsRepository.save(ma2);
			majorsRepository.save(ma3);
			majorsRepository.save(ma4);



			//////////////////////////////////////////////////////////////////////////////////
	/*
			cou1.addStudent(stu2);
			cou2.addStudent(stu3);
			cou3.addStudent(stu1);
			cou3.addStudent(stu4);
			cou3.addStudent(stu6);
			cou4.addStudent(stu5);

			stu1.setCourseTwo(Arrays.asList(cou3));
			stu2.setCourseTwo(Arrays.asList(cou1));
			stu3.setCourseTwo(Arrays.asList(cou2));
			stu4.setCourseTwo(Arrays.asList(cou3));
			stu5.setCourseTwo(Arrays.asList(cou4));
			stu6.setCourseTwo(Arrays.asList(cou3));


	 */
			courseRepository.save(cou1);
			courseRepository.save(cou2);
			courseRepository.save(cou3);
			courseRepository.save(cou4);


		};
	}

}

